home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / idioms.lha / idioms / 9-13.c < prev    next >
Text File  |  1993-08-08  |  1KB  |  37 lines

  1. /* Copyright (c) 1992 by AT&T Bell Laboratories. */
  2. /* Advanced C++ Programming Styles and Idioms */
  3. /* James O. Coplien */
  4. /* All rights reserved. */
  5.  
  6. void
  7. ShapeRep::gcCommon(size_t nbytes, const size_t poolInitialized,
  8.         const int PoolSize, Char_p &heap) {
  9.     size_t s = nbytes? nbytes: poolInitialized;
  10.     size_t Sizeof = Round(s);
  11.     ShapeRep *tp = (ShapeRep *)heap;
  12.     for (int i = 0; i < PoolSize; i++) {
  13.         switch (nbytes) {
  14.         case 0:   // normal garbage collection case
  15.             if (tp->inUse) {
  16.                 if (tp->gcmark || tp->space != FromSpace) {
  17.                     // don't sweep it away
  18.                     tp->space = ToSpace;
  19.                 } else if (tp != tp->type()) {
  20.                     // object needs to be reclaimed
  21.                     tp->ShapeRep::~ShapeRep();
  22.                     tp->inUse = 0;
  23.                     printf("ShapeRep::gcCommon ");
  24.                     printf("Reclaimed Triangle object %c\n",
  25.                      'A' + (((char *)tp-(char *)heap)/Sizeof));
  26.                 }
  27.             }
  28.             break;
  29.         default:   // initialization of memory arena
  30.             tp->inUse = 0;
  31.             break;
  32.         }
  33.         tp->gcmark = 0;
  34.         tp = (ShapeRep*)(Char_p(tp) + Sizeof);
  35.     }
  36. }
  37.